package com.learn.Lock;

import java.util.concurrent.TimeUnit;
/**
 * 1.synchronized 锁的对象是方法的调用者
 * 2.锁两个对象两个方法，两个不同的调用者，两把锁
 */
public class Test03 {

    public static void main(String[] args) {
        sms3 s1 = new sms3();
        sms3 s2 = new sms3();

        new Thread(()->s1.send(),"A").start();
        new Thread(()->s2.recv(),"B").start();
    }
}

class sms3{
    //synchronized 锁的对象是方法的调用者
    public synchronized void send(){
        try {
            TimeUnit.SECONDS.sleep(2);
            System.out.println("send");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public synchronized void recv(){
        System.out.println("recv");
    }
}